package com.download.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.download.web.entity.BusUserHistory;
import com.download.web.entity.model.ArticleListModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description:
 * @author: cmy
 * @create: 2019-03-08 21:08
 **/
public interface BusUserHistoryMapper extends BaseMapper<BusUserHistory> {

    @Select("select a.id,a.create_time,a.browse_num,a.app_name,a.title,a.visible_type,i.`name` typeName,a.under_type as underType ,  " +
            "            im.path img   " +
            " from bus_user_history h " +
            "            LEFT JOIN bus_article a on h.article_id=a.id  " +
            "            LEFT JOIN sys_nav_bar i on a.under_type=i.id   " +
            "            LEFT JOIN bus_images im on a.id=im.article_id    " +
            " where h.user_id=${userId} " +
            " order by a.create_time desc    " +
            " LIMIT ${pageIndex},${pageSize} ")
    List<ArticleListModel> userArticleByHistory(@Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize, @Param("userId") Integer userId);

    @Select("select count(1)  " +
            " from bus_user_history h " +
            "            LEFT JOIN bus_article a on h.article_id=a.id  " +
            "            LEFT JOIN sys_nav_bar i on a.under_type=i.id   " +
            "            LEFT JOIN bus_images im on a.id=im.article_id    " +
            " where h.user_id=${userId} ")
    Integer userArticleByHistoryCount(@Param("userId") Integer userId);

}
